﻿using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
using C1.Win.C1Preview;

namespace PCSUtils.Framework.ReportFrame
{
    public partial class C1PrintPreviewDialog : Form
    {
        private string _reportFile;
        /// <summary>
        /// Gets or sets the report file.
        /// </summary>
        /// <value>The report file.</value>
        public string ReportFile
        {
            get { return _reportFile; }
            set { _reportFile = value; }
        }

        private string _formTitle;
        /// <summary>
        /// Gets or sets the form title.
        /// </summary>
        /// <value>The form title.</value>
        public string FormTitle
        {
            get
            {
                return _formTitle;
            }
            set
            {
                _formTitle = value;
                Text = string.Format("{0} - {1}", TitleLabel.Text, _formTitle);
            }
        }

        /// <summary>
        /// Gets or sets the report viewer.
        /// </summary>
        /// <value>The report viewer.</value>
        public C1PrintPreviewControl ReportViewer
        {
            get
            {
                PreviewControl.PreviewNavigationPanel.Visible = false;
                PreviewControl.PreviewOutlineView.Visible = false;
                PreviewControl.PreviewPane.ZoomMode = ZoomModeEnum.PageWidth;
                return PreviewControl;
            }
        }

        public C1PrintPreviewDialog()
        {
            InitializeComponent();
        }

        private void PreviewControl_KeyDown(object sender, KeyEventArgs e)
        {
            if (string.IsNullOrEmpty(_reportFile))
                return;
            // user press Ctrl + F12, open C1ReportDesigner
            if ((e.KeyCode == Keys.F12) && (e.Modifiers == Keys.Control))
            {
                // look up C1ReportDesigner folder
                var strPath = Path.Combine(Application.StartupPath, @"Designer\C1ReportDesigner.exe");
                var strAgr = Path.Combine(Application.StartupPath, string.Format(@"ReportDefinition\{0}", _reportFile));
                if (File.Exists(strPath))
                {
                    // start new process
                    Process.Start(strPath, strAgr);
                }
            }
        }
    }
}
